<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="日期" prop="dateInfo">
        <el-input v-model="queryParams.dateInfo" placeholder="请输入日期" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="uid" prop="uid">
        <el-input v-model="queryParams.uid" placeholder="uid" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <!-- <el-form-item label="产品ID" prop="productId">
        <el-input v-model="queryParams.productId" placeholder="请输入产品ID" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="产品名称" prop="productName">
        <el-input v-model="queryParams.productName" placeholder="请输入产品名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item> -->
      <!-- <el-form-item label="应用编号" prop="appCode">
        <el-input v-model="queryParams.appCode" placeholder="请输入应用编号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="应用名称" prop="appName">
        <el-input v-model="queryParams.appName" placeholder="请输入应用名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item> -->
      <el-form-item label="渠道编号" prop="channelCode">
        <el-input v-model="queryParams.channelCode" placeholder="请输入渠道编号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="渠道名称" prop="channelName">
        <el-input v-model="queryParams.channelName" placeholder="请输入渠道名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <!-- <el-form-item label="${comment}" prop="randomId">
        <el-input v-model="queryParams.randomId" placeholder="请输入${comment}" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="${comment}" prop="reqIp">
        <el-input v-model="queryParams.reqIp" placeholder="请输入${comment}" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="${comment}" prop="browserName">
        <el-input v-model="queryParams.browserName" placeholder="请输入${comment}" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="${comment}" prop="platformName">
        <el-input v-model="queryParams.platformName" placeholder="请输入${comment}" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item> -->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="small" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="small" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="small" @click="handleAdd"
          v-hasPermi="['product:profitUvInfo:add']">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-edit" size="small" :disabled="single" @click="handleUpdate"
          v-hasPermi="['product:profitUvInfo:edit']">修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="small" :disabled="multiple" @click="handleDelete"
          v-hasPermi="['product:profitUvInfo:remove']">删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="small" @click="handleExport"
          v-hasPermi="['product:profitUvInfo:export']">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="profitUvInfoList">
      <el-table-column label="日期" align="center" prop="dateInfo" />
      <el-table-column label="用户ID" align="center" prop="uid" />
      <el-table-column label="产品ID" align="center" prop="productId" />
      <el-table-column label="产品名称" align="center" prop="productName" />
      <!-- <el-table-column label="应用编号" align="center" prop="appCode" />
      <el-table-column label="应用名称" align="center" prop="appName" /> -->
      <el-table-column label="渠道编号" align="center" prop="channelCode" />
      <el-table-column label="渠道名称" align="center" prop="channelName" />
      <!-- <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="small" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
            v-hasPermi="['product:profitUvInfo:edit']">修改</el-button>
          <el-button size="small" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
            v-hasPermi="['product:profitUvInfo:remove']">删除</el-button>
        </template>
      </el-table-column> -->
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 添加或修改产品收益uv统计信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="日期" prop="dateInfo">
          <el-input v-model="form.dateInfo" placeholder="请输入日期" />
        </el-form-item>
        <el-form-item label="${comment}" prop="uid">
          <el-input v-model="form.uid" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="产品ID" prop="productId">
          <el-input v-model="form.productId" placeholder="请输入产品ID" />
        </el-form-item>
        <el-form-item label="产品名称" prop="productName">
          <el-input v-model="form.productName" placeholder="请输入产品名称" />
        </el-form-item>
        <el-form-item label="应用编号" prop="appCode">
          <el-input v-model="form.appCode" placeholder="请输入应用编号" />
        </el-form-item>
        <el-form-item label="应用名称" prop="appName">
          <el-input v-model="form.appName" placeholder="请输入应用名称" />
        </el-form-item>
        <el-form-item label="渠道编号" prop="channelCode">
          <el-input v-model="form.channelCode" placeholder="请输入渠道编号" />
        </el-form-item>
        <el-form-item label="渠道名称" prop="channelName">
          <el-input v-model="form.channelName" placeholder="请输入渠道名称" />
        </el-form-item>
        <el-form-item label="${comment}" prop="randomId">
          <el-input v-model="form.randomId" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="reqIp">
          <el-input v-model="form.reqIp" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="browserName">
          <el-input v-model="form.browserName" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="platformName">
          <el-input v-model="form.platformName" placeholder="请输入${comment}" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listProfitUvInfo, getProfitUvInfo, delProfitUvInfo, addProfitUvInfo, updateProfitUvInfo } from "@/api/product/profitUvInfo";

export default {
  name: "ProfitUvInfo",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 产品收益uv统计信息表格数据
      profitUvInfoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        dateInfo: null,
        uid: null,
        productId: null,
        productName: null,
        appCode: null,
        appName: null,
        channelCode: null,
        channelName: null,
        randomId: null,
        reqIp: null,
        browserName: null,
        platformName: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        dateInfo: [
          { required: true, message: "日期不能为空", trigger: "blur" }
        ],
        productId: [
          { required: true, message: "产品ID不能为空", trigger: "blur" }
        ],
        productName: [
          { required: true, message: "产品名称不能为空", trigger: "blur" }
        ],
        appCode: [
          { required: true, message: "应用编号不能为空", trigger: "blur" }
        ],
        appName: [
          { required: true, message: "应用名称不能为空", trigger: "blur" }
        ],
        channelCode: [
          { required: true, message: "渠道编号不能为空", trigger: "blur" }
        ],
        channelName: [
          { required: true, message: "渠道名称不能为空", trigger: "blur" }
        ],
        reqIp: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
        createTime: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  watch: {
    $route() {
      this.getList()
    }
  },
  methods: {
    /** 查询产品收益uv统计信息列表 */
    getList() {
      this.loading = true;
      this.queryParams.productId = this.$route.query.productId;
      this.queryParams.dateInfo = this.$route.query.dateInfo;
      listProfitUvInfo(this.queryParams).then(response => {
        this.profitUvInfoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        dateInfo: null,
        uid: null,
        productId: null,
        productName: null,
        appCode: null,
        appName: null,
        channelCode: null,
        channelName: null,
        randomId: null,
        reqIp: null,
        browserName: null,
        platformName: null,
        createTime: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加产品收益uv统计信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getProfitUvInfo(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改产品收益uv统计信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateProfitUvInfo(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addProfitUvInfo(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除产品收益uv统计信息编号为"' + ids + '"的数据项？').then(function () {
        return delProfitUvInfo(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('product/profitUvInfo/export', {
        ...this.queryParams
      }, `profitUvInfo_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
